package cn.chenxinjie.hrm.controller;

import cn.chenxinjie.hrm.dto.SmsDto;
import cn.chenxinjie.hrm.service.IVerifyCodeService;
import cn.chenxinjie.hrm.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.io.IOException;

/**
 * @author 陈鑫杰
 * @date 2022/3/18 15:22
 */
@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {
    @Autowired
    private IVerifyCodeService verifyCodeService;

    /**
     * 生成图片验证码
     * @param key 图片保存到redis中的key
     * @return
     * @throws IOException
     */
    @GetMapping("/imageCode/{key}")
    public AjaxResult createCode(@PathVariable("key") String key) throws IOException {
        return verifyCodeService.createCode(key);
    }

    /**
     * 发送短信验证码
     * @param dto
     * @return
     */
    @PostMapping("/sendSmsCode")
    public AjaxResult sendSmsCode(@RequestBody @Valid SmsDto dto){
        return verifyCodeService.sendSmsCode(dto);
    }
}
